﻿using System.Linq;
using ExtendedMvc.Tests.Model;
using ExtendedMvc.Tests.Model.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ExtendedMvc.Tests {


	/// <summary>
	///This is a test class for ButtonTest and is intended
	///to contain all ButtonTest Unit Tests
	///</summary>
	[TestClass()]
	public class ButtonTest {

		private static DummyDataSource database;
		private static ModelViewPage<Dummy> view;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext { get; set; }

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		[ClassInitialize()]
		public static void MyClassInitialize(TestContext testContext) {
			database = new DummyDataSource();
			var dummy = database.Dummies.All().First();
			view = MvcMockHelpers.FakeViewPage("Index", dummy);
		}

		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup() {
		//}
		//
		//Use TestInitialize to run code before running each test
		[TestInitialize()]
		public void MyTestInitialize() {
			view.ViewContext.ViewData.ModelState.Clear();
		}

		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup() {
		//}
		//
		#endregion

		/// <summary>
		///A test for Button Constructor
		///</summary>
		[TestMethod()]
		public void Button_WithContentOnly() {
			// Arrange
			var buttonContent = "Button Text";
			var expectedOutput = string.Format(@"<button type=""button"">{0}</button>", buttonContent);

			// Act
			var button = view.Html.Button(buttonContent);
			var output = button.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		/// <summary>
		///A test for Button Constructor
		///</summary>
		[TestMethod()]
		public void Button_WithPropertyName() {
			// Arrange
			var buttonContent = "Button Text";
			var buttonId = "buttonId";
			var expectedOutput = string.Format(@"<button id=""{1}"" name=""{1}"" type=""button"">{0}</button>", buttonContent, buttonId);

			// Act
			var button = view.Html.Button(buttonContent, buttonId);
			var output = button.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		/// <summary>
		///A test for Button Constructor
		///</summary>
		[TestMethod()]
		public void Button_WithDisabled() {
			// Arrange
			var buttonContent = "Button Text";
			var buttonId = "buttonId";
			var expectedOutput = string.Format(@"<button disabled=""disabled"" id=""{1}"" name=""{1}"" type=""button"">{0}</button>", buttonContent, buttonId);

			// Act
			var button = view.Html.Button(buttonContent, buttonId).Disabled();
			var output = button.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		/// <summary>
		///A test for Button Constructor
		///</summary>
		[TestMethod()]
		public void Button_WithClick() {
			// Arrange
			var buttonContent = "Button Text";
			var buttonId = "buttonId";
			var onClickEvent = "return false;";
			var expectedOutput = string.Format(@"<button id=""{1}"" name=""{1}"" onclick=""{2}"" type=""button"">{0}</button>", buttonContent, buttonId, onClickEvent);

			// Act
			var button = view.Html.Button(buttonContent, buttonId).OnClick(onClickEvent);
			var output = button.ToString();

			// Assert
			Assert.AreEqual<string>(expectedOutput, output);
		}

		///// <summary>
		/////A test for Button Constructor
		/////</summary>
		//[TestMethod()]
		//public void Button_ForModel() {
		//    // Arrange
		//    var dummy = database.Dummies.All().First();
		//    var expectedValue = dummy.BasicProperty;
		//    var expectedName = "BasicProperty";
		//    var expectedOutput = string.Format(@"<button id=""{1}"" name=""{1}"">{0}</button>", expectedValue, expectedName);

		//    // Act
		//    var button = view.Html.Button(m => m.BasicProperty);
		//    var output = button.ToString();

		//    // Assert
		//    Assert.AreEqual<string>(expectedOutput, output);
		//}
	}
}
